package com.zr.controller.dispatch;

import com.github.pagehelper.PageInfo;
import com.zr.service.dispatch.DispatchMaintenanceService;
import com.zr.utils.AjaxResult;
import com.zr.vo.dispatch.DispatchMaintenance;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author 杜雨萌
 * @date 2022/10/29
 * @version 2022.1
 */
@RestController
@RequestMapping("/dispatch/maintenance")
public class DispatchMaintenanceController {

    @Resource
    private DispatchMaintenanceService dispatchMaintenanceService;


    /**
     * 获得维保列表
     *
     * @param dispatchMaintenance
     * @return
     * @author 杜雨萌
     */
    @PostMapping("list")
    public AjaxResult list(@RequestBody DispatchMaintenance dispatchMaintenance) {
        PageInfo<DispatchMaintenance> pageInfo = dispatchMaintenanceService.list(dispatchMaintenance);
        return AjaxResult.success(200, "查询成功", pageInfo);
    }

    /**
     * 获得状态列表
     *
     * @return
     * @author 杜雨萌
     */
    @PostMapping("statusList")
    public AjaxResult statusList() {
        return AjaxResult.success(200, "查询成功", dispatchMaintenanceService.statusList());
    }

    /**
     * 获得维保类型列表
     *
     * @return
     * @author 杜雨鞥
     */
    @PostMapping("mtTypeList")
    public AjaxResult myTypeList() {
        return AjaxResult.success(200, "查询成功", dispatchMaintenanceService.myTypeList());
    }


    /**
     * 添加维保任务
     *
     * @param dispatchMaintenance
     * @return
     * @author 杜雨萌
     */
    @PostMapping("add")
    public AjaxResult add(@RequestBody DispatchMaintenance dispatchMaintenance) {
        return AjaxResult.success(200, "添加成功", dispatchMaintenanceService.add(dispatchMaintenance));
    }


    /**
     * 编辑列表
     *
     * @param dispatchMaintenance
     * @return
     * @author 杜雨萌
     */
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody DispatchMaintenance dispatchMaintenance) {
        return AjaxResult.success(200, "更新成功", dispatchMaintenanceService.edit(dispatchMaintenance));
    }

    /**
     * 删除维保列表
     *
     * @param id
     * @return
     * @author 杜雨萌
     */
    @PostMapping("remove/{id}")
    public AjaxResult remove(@PathVariable("id") int id) {
        return AjaxResult.success(200, "删除成功", dispatchMaintenanceService.remove(id));
    }

    /**
     * 查询近7天维修保养
     * @return
     * @author liutienan
     */
    @PostMapping("/getRepairRecentWeek")
    public AjaxResult getRepairRecentWeek() {
        return AjaxResult.success(200, "查询成功", dispatchMaintenanceService.getRepairRecentWeek());
    }

    /**
     * 查询近1个月维修保养
     * @return
     * @author liutienan
     */
    @PostMapping("/getRepairRecentMonth")
    public AjaxResult getRepairRecentMonth() {
        return AjaxResult.success(200, "查询成功", dispatchMaintenanceService.getRepairRecentMonth());
    }

    /**
     * 查询近今年维修保养
     * @return
     * @author liutienan
     */
    @PostMapping("/getRepairThisYear")
    public AjaxResult getRepairThisYear() {
        return AjaxResult.success(200, "查询成功", dispatchMaintenanceService.getRepairThisYear());
    }

}
